﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BrainTechLLC.Silverlight.Controls;

namespace BrainTechLLC.Silverlight.ClientApplication
{
    public partial class GameLocationVis1 : UserControl //, ISingleItemDataVisualizer
    {
        //public event EventHandler<ObjectEventArgsNonRef<long>> RequestEditID;
        //public event EventHandler<ObjectEventArgsNonRef<bool>> WantClose;
        //public event EventHandler CloseWindow;        
        public event EventHandler<ObjectEventArgs<GameLocation>> WantViewRoom;
        //public event EventHandler<ObjectEventArgsNonRef<bool>> RequestSave;
        //public event EventHandler Save;

        public void SetVisualizedData(DataVisualizer vis, object o) {  GameLocation = (GameLocation)o; }
        public Type VisualizeType { get { return typeof(GameLocation); } }
        public string VisualizerName { get { return "GameLocationVis1"; } }
        public WindowContainer Window { get { return null; } }
        public bool HideHeader { get { return true; } set { } }
        public bool ShowScroller { get { return true; } set { } }
        public Panel MainCanvas { get { return MainCanvas; } }
        
        public void Refresh()
        {
        }

        public bool IsOpen { get { return true; } set { } }
        public bool ShowEdit { get { return true; } set { } }
        public bool ShowSave { get { return true; } set { } }

        public bool ShowClose
        {
            get { return (bool)GetValue(WindowContainer.ShowCloseProperty); }
            set { SetValue(WindowContainer.ShowCloseProperty, value); }
        }

        public static readonly DependencyProperty GameLocationProperty = DependencyProperty.Register(
            "GameLocation", typeof(GameLocation), typeof(GameLocationVis1), new PropertyMetadata(null, new PropertyChangedCallback(GameLocationChanged)));

        public GameLocation GameLocation
        {
            get { return (GameLocation)GetValue(GameLocationProperty); }
            set { SetValue(GameLocationProperty, value); }
        }

        private static void GameLocationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GameLocationVis1 t = (GameLocationVis1)d;
            t.GameLocation = (GameLocation)e.NewValue;
            t.RebindThing();
        }

        public void RebindThing()
        {
            canvasMain.DataContext = GameLocation;
        }

        public static readonly DependencyProperty DisplayXProperty = DependencyProperty.Register(
            "DisplayX", typeof(int), typeof(GameLocationVis1), new PropertyMetadata(0, new PropertyChangedCallback(DisplayXChanged)));

        public int DisplayX
        {
            get { return (int)GetValue(DisplayXProperty); }
            set { SetValue(DisplayXProperty, value); }
        }

        private static void DisplayXChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GameLocationVis1 t = (GameLocationVis1)d;
            t.DisplayX = (int)e.NewValue;
        }


        public static readonly DependencyProperty DisplayYProperty = DependencyProperty.Register(
            "DisplayY", typeof(int), typeof(GameLocationVis1), new PropertyMetadata(0, new PropertyChangedCallback(DisplayYChanged)));

        public int DisplayY
        {
            get { return (int)GetValue(DisplayYProperty); }
            set { SetValue(DisplayYProperty, value); }
        }

        private static void DisplayYChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GameLocationVis1 t = (GameLocationVis1)d;
            t.DisplayY = (int)e.NewValue;
        }

        public GameLocationVis1()
        {
            InitializeComponent();
        }

        private void btnView_Click(object sender, RoutedEventArgs e)
        {
            if (WantViewRoom != null)
                WantViewRoom(this, new ObjectEventArgs<GameLocation>(GameLocation));
        }
    }
}
